//
//  LRXContentView.m
//  路人侠
//
//  Created by zhangxulong on 2/8/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXContentView.h"
#import "LRXThingView.h"
#import "LRXThing.h"
#import "UIColor+LRXColorRGB.h"
#import "NSString+LRXStringCategory.h"
#import "zxlCircleView.h"
#import "RervsecodeViewController.h"
#import "LRXSelectTimeInputView.h"
#import "KLSwitch.h"
#import "LRXBedRoomView.h"
#import "LRXBuyThingCell.h"
static NSString * locationAddr = @"送达地点";
static NSString * buyAddr = @"购买地点";

@interface LRXContentView()<
    UITextViewDelegate,
    RervsecodeViewControllerDelegate,
    selectTimeInputViewDelegate,
    bedRoomDelegate
>

@property (nonatomic,strong) RervsecodeViewController * location;
@property (nonatomic,weak) UIView * backgroundView;
@property (nonatomic,assign) CGFloat maxY;
@property (nonatomic,assign) NSInteger  selectMinues;
@property (nonatomic,assign) NSInteger  selectHour;
@property (nonatomic,weak) UILabel * sendTimeLabel;
@property (nonatomic,weak) UILabel * sendHomeLabel;
@property (nonatomic,strong) LRXBedroom * bedRoomData;
@property (nonatomic,weak) LRXBedRoomView * selectBedView;
@property (nonatomic,weak) UILabel * tipLabel;
@property (nonatomic,weak) UILabel * tipLabelText;
@property (nonatomic,weak) UILabel * remaind;
@property (nonatomic,weak) UILabel * sumCheck;
@property (nonatomic,weak) UILabel * sumMoney;
@property (nonatomic,weak) UIImageView * carveImage;
@property (nonatomic,weak) UIView * lineView3;
@property (nonatomic,strong) UIView * thingContent;
@property (nonatomic,weak) UIButton * moreBtn;
@property (nonatomic,weak) UIButton * addThingBtn;
@property (nonatomic,weak) UITextField * switchText;
@property (nonatomic,weak) KLSwitch * switchBtn;
@property (nonatomic,weak) UILabel * bedRoomLabel;


@end

@implementation LRXContentView
//各种懒加载
- (UIView *)thingContent
{
    if (_thingContent == nil) {
        _thingContent = [[UIView alloc]init];
    }
    return _thingContent;
}
- (UITextView *)mesgView
{
    if (_mesgView == nil) {
        _mesgView = [[UITextView alloc]init];
    }
    return _mesgView;
}


- (RervsecodeViewController *)location
{
    if (_location == nil) {
        _location = [[RervsecodeViewController alloc]init];
    }
    return _location;
}

- (NSMutableArray *)thingArray
{
    if (_thingArray == nil) {
        _thingArray = [NSMutableArray array];
   
    }
    return _thingArray;
}


- (void)layoutContentView
{
    
    
   
    
    //设置地址样式
    [self addAddrcView];
    //设置内容样式
    [self addSubThingView];
    //物品动态摆设布局
    [self layoutThingView];
    
    //设置送货时间label的样式
    [self addSendTime];
    
    //设置 送货上门 和 金钱 字样
    [self sumCheckTip];
    
    //留言区域 布局
    [self wMessage];
    
    RervsecodeViewController * location = [[RervsecodeViewController alloc]init];
    location.locationDelegate = self;
    [location locationGD];
    
    //定位开始  如果是 弱引用 就会消失
//    self.location.locationDelegate = self;
//    [self.location locationGD];
    
    
 
}

- (void)addAddrcView
{
    
    CGFloat spotRadius = 16 * hScale;
    CGFloat addrBtnX = 80 * wScale;
    
    
    //地址的初始化
    self.sendAddrText = locationAddr;
    
    UILabel * sendlabel = [[UILabel alloc]init];
    sendlabel.text = @"收货地点";
    sendlabel.textColor = [UIColor colorWithRed:115 green:115 blue:115];
    sendlabel.frame = CGRectMake(addrBtnX, 48 * hScale, 500 * wScale, 28 * hScale);
    sendlabel.font = [UIFont systemFontOfSize:28 * hScale];
    self.sendlabel = sendlabel;

    
        //画线
    UIView *  lineView = [[UIView alloc]init];
    lineView.backgroundColor = [UIColor colorWithRed:222 green:222 blue:222];
    CGFloat lineY = CGRectGetMaxY(self.sendlabel.frame) + 18 * hScale;
    lineView.frame = CGRectMake(80 * wScale, lineY,self.frame.size.width - 80 * hScale,2 * hScale);
    
    //设置购物地点样式
    CGFloat AddrBtnY = lineY + 26 * hScale;

    UIButton *  sendAddrBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.sendAddrBtn = sendAddrBtn;
    //设置送达地点字样 样式
    [self.sendAddrBtn setTitle:locationAddr forState:UIControlStateNormal];
    [self.sendAddrBtn setTitleColor:[UIColor colorWithRed:115 green:115 blue:115] forState:UIControlStateNormal];
    self.sendAddrBtn.titleLabel.font = [UIFont systemFontOfSize:28 * hScale];
    self.sendAddrBtn.frame = CGRectMake(addrBtnX, AddrBtnY , 500 * wScale, 28 * hScale);
    self.sendAddrBtn.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
    
    [self.sendAddrBtn addTarget:self action:@selector(pushAddrcInfoController:) forControlEvents:UIControlEventTouchUpInside];
    self.sendAddrBtn.tag = SENDADDRBTNFLAG;
    

    //画线
    UIView * lineView2 = [[UIView alloc]init];
    lineView2.backgroundColor = [UIColor colorWithRed:222 green:222 blue:222];
    CGFloat line2Y = CGRectGetMaxY(self.sendAddrBtn.frame) + 24 * hScale;
    lineView2.frame = CGRectMake(0, line2Y,self.frame.size.width ,2 * hScale);
    


    zxlCircleView * endSpot = [[zxlCircleView alloc]init];
    endSpot.imageName = @"stSpot";
    
    endSpot.frame = CGRectMake(0, 0, spotRadius, spotRadius);
    CGPoint endPoint = CGPointMake(43 * wScale, self.sendlabel.center.y);
    endSpot.center = endPoint;
    endSpot.backgroundColor = [UIColor clearColor];
    
    
    [self addSubview:endSpot];
    
    
    
    self.maxY = line2Y;
    [self addSubview:lineView2];
    [self addSubview:self.sendlabel];
    [self addSubview:self.sendAddrBtn];
}
- (void)addSubThingView
{
    //根据thing的个数和大小动态 合理排版布局
    CGFloat thingViewY = 220 * hScale;
    CGFloat thingH = 57 * hScale;
    
    
    self.thingContent.frame = CGRectMake(37 * wScale, thingViewY, 543 * wScale, thingH);
    
    [self addSubview:self.thingContent];
    
    UIButton * moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.moreBtn = moreBtn;
    [self.moreBtn setTitle:@"添加物品" forState:UIControlStateNormal];
    self.moreBtn.backgroundColor = mainColor;
    self.moreBtn.layer.cornerRadius = 5 * hScale;
    self.moreBtn.frame = CGRectMake(400 * wScale,thingViewY + 5 * hScale , 200 * wScale, 60 * hScale);  //333
    self.moreBtn.titleLabel.font = [UIFont systemFontOfSize:28 * hScale];
    [self.moreBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.moreBtn.tag = 1;
    [self.moreBtn addTarget:self action:@selector(moreThingInfo:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.moreBtn];

    //展开更多内容界面的按钮
    UIButton * addThingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.addThingBtn = addThingBtn;
    self.addThingBtn.tag = 0;
    self.addThingBtn.backgroundColor = [UIColor whiteColor];
    [self.addThingBtn addTarget:self action:@selector(moreThingInfo:) forControlEvents:UIControlEventTouchUpInside];
    [self.addThingBtn setImage:[UIImage imageNamed:@"morebtn"] forState:UIControlStateNormal];
    self.addThingBtn.imageEdgeInsets = UIEdgeInsetsMake(30 * hScale, 30 * wScale, 0, 15 * wScale);
    self.addThingBtn.frame = CGRectMake(580 * wScale, thingViewY + 5 * hScale, 60 * wScale, 50 *  hScale);
    [self addSubview:self.addThingBtn];
    

    self.maxY = MAX(CGRectGetMaxY(self.moreBtn.frame), self.maxY);

}

//物品的 动态布局
- (void)layoutThingView
{
    
    //根据thing的个数和大小动态 合理排版布局
    CGFloat thingViewY = 220 * hScale;
    CGFloat thingViewX = 0;
    CGFloat thingInterval = 30 * wScale;   //物品和物品的间隔
    CGFloat thingEage = 20 * wScale;       //物品按钮的内边距
    CGFloat thingH = 57 * hScale;
    
    //创建一个thingCountView 每一次重新布局的时候 清空view的自控件
    for (UIView * subView in self.thingContent.subviews) {
        [subView removeFromSuperview];
    }
    
    self.thingContent.frame = CGRectMake(37 * wScale, thingViewY, 543 * wScale, thingH);
    //遍历thing，排版thing的布局
    for (int i = 0; i < self.thingArray.count; i++) {
        //建立一个Thing的视图
        LRXThingView * thingView = [[LRXThingView alloc]init];
        
        
        [thingView layoutThingSubviews:self.thingArray[i]];
        
        //thing的边框线
        thingView.layer.cornerRadius = 5 * hScale;
        thingView.layer.borderWidth = 2 * hScale;
        thingView.layer.borderColor = mainColor.CGColor;
        
        //thing的大小位置，如果一行超过了，就放两行
        if (thingViewX + thingView.thingWidth + 50 * wScale > 543 * wScale)
            break;
        
        else
        {
            thingView.frame = CGRectMake(thingViewX, 0, thingEage * 2 + thingView.thingWidth, thingH);
        }
        
        //这是更多按钮
        thingViewX += (thingInterval + thingEage * 2);
        thingViewX += thingView.thingWidth;
        self.maxY = CGRectGetMaxY(thingView.frame);
        [self.thingContent addSubview:thingView];
    }
    
    if (self.thingContent.subviews.count <= 0) {
        self.addThingBtn.hidden = YES;
        self.moreBtn.hidden = NO;
    }
    else{
        self.addThingBtn.hidden = NO;
        self.moreBtn.hidden = YES;
    }

    CGFloat sumMoney = 0;
    for (LRXThing * thing in self.thingArray) {
        sumMoney += [thing.thingMoney floatValue] * [thing.thingCount floatValue];
    }
    
    self.tipLabelText.text = [NSString stringWithFormat:@"%.2lf 元",sumMoney * 0.1];
    self.sumMoney.text = [NSString stringWithFormat:@"%.2lf 元",sumMoney];
    
    
    self.maxY = MAX(CGRectGetMaxY(self.moreBtn.frame), self.maxY);
}

//送达时间 设置
- (void)addSendTime
{
    //送到时间 字样 布局

    CGFloat sendTimeY = self.maxY + 80 * hScale;
    UILabel * sendTimeLabel = [[UILabel alloc]init];
    self.sendTimeLabel = sendTimeLabel;
    self.sendTimeLabel.frame = CGRectMake(38 * wScale, sendTimeY, 0, 0);
    [self.sendTimeLabel setText:@"预期送达时间："];
    self.sendTimeLabel.font = [UIFont systemFontOfSize:28 * hScale];
    [self.sendTimeLabel sizeToFit];
    
    
    
    NSString * stHourStr = [NSString stringWithFormat:@"%02ld",[LRXGetTime getHour]];
    NSString * stMinuStr = [NSString stringWithFormat:@"%02ld",[LRXGetTime getMinute]];
    NSString * endHour = [NSString stringWithFormat:@"%02ld",[LRXGetTime getHour] + 1];
    //开始时间提示text布局
    
    
    self.startTimeField = [[UITextField alloc]init];
    self.startTimeField.textAlignment = NSTextAlignmentCenter;
    CGFloat startBtnX = 420 * wScale;
    self.startTimeField.frame = CGRectMake(startBtnX, sendTimeY, 80 * wScale, 36 * hScale);
    self.startTimeField.font = [UIFont systemFontOfSize:24 * hScale];
    self.startTimeField.text = [NSString stringWithFormat:@"%@:%@",stHourStr,stMinuStr];
    self.startTimeField.textColor = mainColor;
    [self.startTimeField addTarget:self action:@selector(keyboardWillChangeFrame) forControlEvents:UIControlEventEditingDidBegin];
    
    
    //时间之间的分割线 布局
    UIView * stToEnd = [[UIView alloc]init];
    stToEnd.backgroundColor = [UIColor blackColor];
    CGFloat stToEndCenterX = CGRectGetMaxX(self.startTimeField.frame) + 7 * wScale;
    stToEnd.bounds = CGRectMake(0,0, 25 * wScale,2 * wScale);
    stToEnd.center = CGPointMake(stToEndCenterX + 12 * wScale, self.startTimeField.center.y);
    
    
    
    //结束时间提示按钮 布局
    self.endTimeField = [[UITextField alloc]init];
    self.endTimeField.textAlignment = NSTextAlignmentCenter;
    CGFloat endTimeBtnX = stToEnd.frame.origin.x + stToEnd.frame.size.width + 8 * wScale;
    self.endTimeField.frame = CGRectMake(endTimeBtnX, sendTimeY, 80 * wScale, 36 * hScale);
    self.endTimeField.font = [UIFont systemFontOfSize:24 * hScale];
    self.endTimeField.text = [NSString stringWithFormat:@"%@:%@",endHour,stMinuStr];
    self.endTimeField.textColor = mainColor;
    
    [self.endTimeField addTarget:self action:@selector(keyboardWillChangeFrame) forControlEvents:UIControlEventEditingDidBegin];
    self.maxY = self.sendTimeLabel.frame.origin.y + self.sendTimeLabel.frame.size.height;
    
    LRXSelectTimeInputView * inputView = [[LRXSelectTimeInputView alloc]init];
    inputView.bounds = CGRectMake(0, 0,self.frame.size.width, 350 * hScale);
   
    NSArray * nowTime = @[stHourStr,stMinuStr,endHour,stMinuStr];
    inputView.selectTimeDelegate = self;
    [inputView selectTimeInputView:nowTime];
    
    
    self.startTimeField.inputView = inputView;
    self.endTimeField.inputView = inputView;
    
    [self addSubview:stToEnd];
    [self addSubview:self.endTimeField];
    [self addSubview:self.startTimeField];
    [self addSubview:self.sendTimeLabel];
}

//送货上门 和 小费 字样
- (void)sumCheckTip
{
    
    //设置 送货上门 字样 布局
    UILabel * sendHomeLabel  = [[UILabel alloc]init];
    self.sendHomeLabel = sendHomeLabel;
    self.sendHomeLabel.text = @"送货上楼：";
    CGFloat sendHomeLabelY = self.maxY + 46 * hScale;
    self.sendHomeLabel.frame = CGRectMake(36 * wScale, sendHomeLabelY, 120 * wScale, 76 * hScale);
    self.sendHomeLabel.font = [UIFont systemFontOfSize:28 * hScale];
    [self.sendHomeLabel sizeToFit];
    [self addSubview:self.sendHomeLabel];
    
    UILabel * bedRoomLabel = [[UILabel alloc]init];
    bedRoomLabel.font = sendHomeLabel.font;
    bedRoomLabel.textColor = orangeColor;
    bedRoomLabel.text = @"";
    bedRoomLabel.textAlignment = NSTextAlignmentLeft;
    bedRoomLabel.frame = CGRectMake(CGRectGetMaxX(sendHomeLabel.frame) + 10 * wScale, sendHomeLabelY, 0, 0);
    [bedRoomLabel sizeToFit];
    
    self.bedRoomLabel = bedRoomLabel;
    [self addSubview:bedRoomLabel];
    
    
    LRXBedRoomView * selectBedView = [[LRXBedRoomView alloc]init];
    selectBedView.backgroundColor = orangeColor;
    selectBedView.frame = CGRectMake(0, self.frame.size.height - 350 * hScale, MainScreenW, 350 * hScale);
    [selectBedView layoutBedRoom:self.bedRoomData];
    selectBedView.delegate = self;
    self.selectBedView = selectBedView;
   
    
    UITextField * switchText = [[UITextField alloc]init];
    self.switchText = switchText;
    [self addSubview:switchText];
    switchText.inputView = selectBedView;
    
    
    KLSwitch * switchBtn = [[KLSwitch alloc]initWithFrame:CGRectMake(0, 0, 60 * wScale, 40 * hScale) didChangeHandler:^(BOOL isOn) {
        
        if([self.bedRoomData isEqual:[NSNull null]] || !self.bedRoomData)
        {
            [MBProgressHUD showError:@"送货地址无效"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.switchBtn setOn:NO animated:YES];
            });
        }
        else
            [self KLSwitchisOn:isOn];
    }];
    [switchBtn setOnTintColor:mainColor];
    switchBtn.center = CGPointMake(560 * wScale, self.sendHomeLabel.center.y);
    self.switchBtn = switchBtn;
    [self addSubview:switchBtn];
    
    
    
    self.thingMoneySum = 0;
    for (LRXThing * thing in self.thingArray) {
        self.thingMoneySum += [thing.thingMoney floatValue] * [thing.thingCount integerValue];
    }
    //设置 小费字样 布局
    
    UILabel * tipLabel = [[UILabel alloc]init];
    self.tipLabel = tipLabel;
    self.tipLabel.text = @"小费:";
    
    CGFloat tiplabelY = CGRectGetMaxY(self.sendHomeLabel.frame) + 90 * hScale;
    self.tipLabel.frame = CGRectMake(36 * wScale, tiplabelY, 0, 0);
    self.tipLabel.font = [UIFont systemFontOfSize:28 * hScale];
    [self.tipLabel sizeToFit];
    
    
    UILabel * tipLabelText = [[UILabel alloc]init];
    self.tipLabelText = tipLabelText;
    self.tipLabelText.font = [UIFont systemFontOfSize:28 * hScale];
    CGFloat tipTextX = CGRectGetMaxX(self.tipLabel.frame) + 36 * wScale;
    self.tipLabelText.frame = CGRectMake(tipTextX, tiplabelY, 80 * wScale, 37 * hScale);
    self.tipLabelText.text = [NSString stringWithFormat:@"%.2lf 元",self.thingMoneySum / 10];
    self.tipLabelText.textColor = orangeColor;
    
    UIImageView * carveImage = [[UIImageView alloc]init];
    self.carveImage = carveImage;
    CGFloat carveImageX = 312 * wScale;
    self.carveImage.image = [UIImage imageNamed:@"carve"];
    self.carveImage.frame = CGRectMake(carveImageX, tiplabelY,1 * wScale, self.tipLabel.frame.size.height);
    [self.tipLabelText sizeToFit];
    
    
    UILabel * sumCheck = [[UILabel alloc]init];
    self.sumCheck = sumCheck;
    CGFloat sumCheckX = carveImageX + 44 * wScale;
    self.sumCheck.text = @"合计:";
    self.sumCheck.font = [UIFont systemFontOfSize:29 * hScale];
    self.sumCheck.frame = CGRectMake(sumCheckX, tiplabelY, 0, 0);
    [self.sumCheck sizeToFit];
    
    UILabel * sumMoney = [[UILabel alloc]init];
    self.sumMoney = sumMoney;
    CGFloat sumMoneyX = sumCheckX + self.sumCheck.frame.size.width + 30 * wScale;
    self.sumMoney.font = [UIFont systemFontOfSize:28 * hScale];
    self.sumMoney.frame = CGRectMake(sumMoneyX, tiplabelY, 100 * wScale, 30 * hScale);
    self.sumMoney.text = [NSString stringWithFormat:@"%.2lf 元",self.thingMoneySum];
    self.sumMoney.textColor = orangeColor;
    
    
    
    UILabel * remaind = [[UILabel alloc]init];
    self.remaind = remaind;
    self.remaind.text = @"小费收取标准按物价的10%收取";
    self.remaind.font =[UIFont systemFontOfSize:20 * hScale];
    self.remaind.textColor = mainGrayColor;
    self.remaind.frame = CGRectMake(36 * wScale, CGRectGetMaxY(self.tipLabel.frame) + 20 * hScale, 0, 0);
    [self.remaind sizeToFit];
    
    self.maxY = CGRectGetMaxY(self.remaind.frame) + 20 *hScale;
    
    [self addSubview:self.remaind];
    [self addSubview:self.tipLabelText];
    [self addSubview:self.tipLabel];
    [self addSubview:self.carveImage];
    [self addSubview:self.sumCheck];
    [self addSubview:self.sumMoney];
    
    
}

//留言 板块
- (void)wMessage
{
   
    UIView * lineView3 = [[UIView alloc]init];
    self.lineView3 = lineView3;
    self.lineView3.backgroundColor = [UIColor colorWithRed:222 green:222 blue:222];
    CGFloat lineY = self.maxY + 24 * hScale;
    self.lineView3.frame = CGRectMake(0,lineY , MainScreenW, 2 * hScale);
    [self addSubview:self.lineView3];
    
    self.mesgView = [[UITextView alloc]init];
    self.mesgView.frame = CGRectMake(25 * wScale, lineY + 30 * hScale, MainScreenW - 56 * wScale, self.frame.size.height - lineY - 30 * hScale);
    self.mesgView.font = [UIFont systemFontOfSize:24 * hScale];
    self.mesgView.text = @"备注";
    
    
    self.mesgView.delegate = self;
    self.mesgView.textColor = [UIColor colorWithRed:115 green:115 blue:115];
//    [self addSubview:self.mesgView];
    
    self.maxY = self.mesgView.frame.origin.y + self.mesgView.frame.size.height;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self KLSwitchisOn:NO];
    [self.backgroundView removeFromSuperview];
    [self endEditing:YES];
}
//-----------------------------------------------------------------------------------------------------textViewDelegate 的代理方法
//开始编辑的时候
- (void)textViewDidBeginEditing:(UITextView *)textView {
    
    float offset = 0.0f;
    if ([textView.text isEqualToString:@"备注"]) {
        textView.text = @"";
    }
    
    if(self.mesgView == textView)
        
    {
        offset = - 180.0f;
        
    }
    
    NSTimeInterval animationDuration = 0.30f;
    
    [UIView beginAnimations:@"ResizeForKeyBoard"context:nil];
    
    [UIView setAnimationDuration:animationDuration];
    
    float width = self.frame.size.width;
    
    float height = self.frame.size.height;
    
    CGRect rect = CGRectMake(0.0f, offset , width, height);
    
    self.frame = rect;
    
    [UIView  commitAnimations];
}
//编辑的 时候
- (void)textViewDidChange:(UITextView *)textView{
    float offset = 0.0f;
    CGFloat megH;
    
    if(self.mesgView == textView)
    {
        megH = textView.frame.size.height - [textView.text sizeWithMaxSize:textView.frame.size fontSize:24 * hScale].height ;
        if (megH < (260 - 24 * hScale)) {
            offset = megH - 260;
        }
        
    }
    
    NSTimeInterval animationDuration = 0.30f;
    
    [UIView beginAnimations:@"ResizeForKeyBoard"context:nil];
    
    [UIView setAnimationDuration:animationDuration];
    
    float width = self.frame.size.width;
    
    float height = self.frame.size.height;
    
    CGRect rect = CGRectMake(0.0f, offset , width, height);
    
    self.frame = rect;
    
    [UIView  commitAnimations];
    
    
}

//在结束编辑的代理方法中进行如下操作
- (void)textViewDidEndEditing:(UITextView *)textView {
    if (textView.text.length<1) {
        textView.text = @"备注";
    }
    
    NSTimeInterval animationDuration = 0.30f;
    
    [UIView beginAnimations:@"ResizeForKeyBoard"context:nil];
    
    [UIView setAnimationDuration:animationDuration];
    
    float width = self.frame.size.width;
    
    float height = self.frame.size.height;
    
    CGRect rect = CGRectMake(0.0f, 0 , width, height);
    
    self.frame = rect;
    
    [UIView commitAnimations];
}

//-------------------------------------------------------------------------------------------------------地图定位的回调函数仅在定位的时候调用
- (void)updateLocation:(NSString *)locationText
{
    self.locationAddr = locationText;
    if (![self.sendAddrText isEqualToString:locationText] && [self.sendAddrText isEqualToString:@"送达地点"]) {
         self.sendAddrText = locationText;
        [self.sendAddrBtn setTitle: self.sendAddrText forState:UIControlStateNormal];
    }
}

- (void)setSendAddr:(NSString *)sendAddrStr withBedroom:(LRXBedroom *)bedRoom
{
//    locationAddr = sendAddrStr;
    self.sendAddrText = sendAddrStr;
    self.bedRoomData = bedRoom;
    if (![self.bedRoomData isEqual:[NSNull null]] || !self.bedRoomData) {
        [self.selectBedView reloadNewData: self.bedRoomData];
    }
    self.bedRoomLabel.text = @"";
    self.bedRoomBlockStr = @"";
    self.bedRoomStr = @"";
    [self.switchBtn setOn:NO];
    [self.sendAddrBtn setTitle:self.sendAddrText forState:UIControlStateNormal];
}

//--------------------------------------------------------------------------------------------点击地址的按钮 代理 controller 实现界面跳转
- (void)pushAddrcInfoController:(UIButton * )btn
{
    if ([self.moreThingInfoDelegate respondsToSelector:@selector(clickAddAddrcBtn:flag:)]) {
        [self.moreThingInfoDelegate clickAddAddrcBtn:self flag:btn.tag];
    }
}
//--------------------------------------------------------------------------------------------展开更多物品的界面  代理 controller 实现显示更多的物品跳转
/**
 *  添加物品按钮
 *
 *  @param btn tag 为 0  底部弹出更多物品
 *  @param btn tag 为 1  路人侠商店
 */
- (void)moreThingInfo:(UIButton *)btn{
    if (btn.tag == 0) {
        if ([self.moreThingInfoDelegate respondsToSelector:@selector(clickMoreThingInfoBtn)])
        {
            [self.moreThingInfoDelegate clickMoreThingInfoBtn];
        }
    }
    else
    {
        if ([self.moreThingInfoDelegate respondsToSelector:@selector(pushBuyThingView)]) {
            [self.moreThingInfoDelegate pushBuyThingView];
        }
    }
}
#pragma mark - selectTimeInputView的代理方法
- (void)selectTimeInputView:(LRXSelectTimeInputView *)inputView withInputViewTag:(NSInteger)inputTag
{
    if (inputTag == 0) {
        NSRange range = {2,3};
        NSString * stMinu = [self.startTimeField.text substringWithRange:range];
        self.startTimeField.text =  [NSString stringWithFormat:@"%02ld%@",inputView.stHour,stMinu];
    }
    if (inputTag == 1) {
        NSRange range = {0,3};
        NSString * stMinu = [self.startTimeField.text substringWithRange:range];
        self.startTimeField.text =  [NSString stringWithFormat:@"%@%02ld",stMinu,inputView.stMinu];
    }
    if (inputTag == 2) {
        NSRange range = {2,3};
        NSString * endHour = [self.endTimeField.text substringWithRange:range];
        self.endTimeField.text =  [NSString stringWithFormat:@"%02ld%@",inputView.endHour,endHour];
    }
    if (inputTag == 3) {
        NSRange range = {0,3};
        NSString * endMinu = [self.endTimeField.text substringWithRange:range];
        self.endTimeField.text =  [NSString stringWithFormat:@"%@%02ld",endMinu,inputView.endMinu];
    }
}
#pragma mark - bedRoomDelegate
- (void)bedRoomSelectWithFloorNum:(NSString *)floorNum withBlockNum:(NSString *)BlockNum
{
    NSString * pp = [floorNum stringByAppendingString:BlockNum];
    self.bedRoomLabel.text = pp;
    self.bedRoomBlockStr = pp;
    [self.bedRoomLabel sizeToFit];
    
    if (![BlockNum isEqual:[NSNull null]] && BlockNum.length > 0 ) {
        NSRange  rang = {0,BlockNum.length-1};
        self.bedRoomStr = [BlockNum substringWithRange:rang];
    }
    
}

#pragma mark - 键盘弹出的通知
- (void)keyboardWillChangeFrame
{
    UIView * backgroundView = [[UIView alloc]init];
    backgroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.54];
    backgroundView.frame = CGRectMake(0, -self.navH, MainScreenW, MainScreenH);
    self.backgroundView = backgroundView;
    [self addSubview:backgroundView];
}
- (void)mengbanClick
{
    [self.switchText resignFirstResponder];
    [self.backgroundView removeFromSuperview];
    [self endEditing:YES];
}

- (void)KLSwitchisOn:(BOOL)isOn
{
    if (isOn) {
        [self.switchText becomeFirstResponder];
        [self keyboardWillChangeFrame];
    }
    else{
        [self.switchText resignFirstResponder];
        [self mengbanClick];
    }
    

}

@end
